package com.syedu.day15.homework;

/**
 * 编写10个线程，第一个线程从1加到10，第二个线程从11加20…第十个线程从91加到100，最后再把10个线程结果相加
 */
public class Exercise3 {
    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            int k = i * 10 + 1;
            MyThread add = new MyThread(k);
            add.start();
            try {
                Thread.sleep(30);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        System.out.println("10个线程结果相加为：" + MyThread.sum);
    }
}

class MyThread extends Thread {
    static int sum;
    private int number;

    public MyThread(int n) {
        number = n;
    }

    @Override
    public void run() {


        int count = 0;
        for (int i = 0; i < 10; i++) {
            count = count + number + i;
        }
        System.out.println(number + "+" + (number + 1) + "+" + (number + 2) + "+" + (number + 3) + "+" + (number + 4)
                + "+" + (number + 5) + "+" + (number + 6) + "+" + (number + 7) + "+" + (number + 8) + "+" + (number + 9)
                + "=" + count);
        sum = sum + count;
    }
}